package org.example.y24.m11;

import java.util.Scanner;

public class MainE {
    public static void main(String[] args) {
        while (true){
            Scanner sc = new Scanner(System.in);
            int T = sc.nextInt();
            while (T > 0) {
                int N = sc.nextInt();
                int[][] arr = new int[N][N];
                for (int i = 0; i < N; i++) {
                    //横向判断
                    for (int j = 0; j < N; j++) {
                        if (i % 2 == 0){
                            if (j % 2 == 0 && j < N) {
                                arr[i][j] = 1;
                            }else{
                                arr[i][j] = 0;
                            }
                        }else {

                        }
                    }
                }
                for (int i = 0; i < N; i++) {
                    for (int j = 0; j < N; j++) {
                        System.out.print(arr[i][j] + " ");
                    }
                    System.out.println();
                }
                T--;
            }
        }
    }
}
